<%--
  Created by IntelliJ IDEA.
  User: bb
  Date: 2021/10/20
  Time: 20:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="jquery-easyui-1.7.0/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="jquery-easyui-1.7.0/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="jquery-easyui-1.7.0/demo/demo.css" rel="stylesheet" type="text/css" />
    <script src="jquery-easyui-1.7.0/jquery.min.js" type="text/javascript"></script>
    <script src="jquery-easyui-1.7.0/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
</head>
<body>
    <div id="datagrid_user" class="easyui-datagrid"></div><%--datagrid--%>
    <div id="header_user" style="padding: 4px 3px">
        <form>
            客户名称：&nbsp;<input class="easyui-textbox" id="userName_user" name="userName_user" style="width: 110px"/>&nbsp;&nbsp;
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="searchUserInfo();">查找</a>
        </form>
    </div><%--header--%>
    <div id="toolbar_user">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" plain="true" onclick="ChangeUserStatus(1);">启用</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-no" plain="true" onclick="ChangeUserStatus(0);">禁用</a>
    </div><%--toolbar--%>

    <script>
        $(function (){
            $('#datagrid_user').datagrid({
                url:'userInfo/getUsers',
                singleSelect:false,
                pagination:true,
                pageSize:10,
                pageList:[5,10,15,20],
                fit:true,
                header:'#header_user',
                toolbar:'#toolbar_user',
                columns:[[{
                    title:'序号',
                    field:'id',
                    checkbox:true,
                    align:'center'
                },{
                    title: '用户名',
                    field: 'userName',
                    width:80
                },{
                    title: '真实姓名',
                    field: 'realName',
                    width:80
                },{
                    title: '性别',
                    field: 'sex',
                    align: 'center',
                    width:50
                },{
                    title: '住址',
                    field: 'address',
                    width:180
                },{
                    title: '电子邮箱',
                    field: 'email',
                    width:180
                },{
                    title: '注册日期',
                    field: 'regDate',
                    width:120
                },{
                    title: '客户状态',
                    field: 'status',
                    width:80,
                    align: 'center',
                    formatter:function (value, row, index){
                        if(row.status == 1){
                            return '已启用';
                        }
                        return '已禁用';
                    }
                }]]
            });
        });
    </script><%--datagrid--%>
    <script>
        function searchUserInfo(){
            var userName = $('#userName_user').textbox('getValue');
            $('#datagrid_user').datagrid('load',{
                userName:userName,
            })
        }
    </script><%--searchBar--%>
    <script>
        function ChangeUserStatus(flag){
            var rows = $("#datagrid_user").datagrid('getSelections');
            var len = rows.length;
            if ( len ){
                $.messager.confirm('Confirm', '确认要设置吗？', function (r){
                    if (r) {
                        var ids = "";
                        for (var i = 0; i < len; i++) {
                            ids += rows[i].id;
                            if (i + 1 != len) {
                                ids += ',';
                            }
                        }
                        $.post('userInfo/updateUserStatus', {
                            flag: flag,
                            ids: ids,
                        }, function (result) {
                            if (result.success == "true") {
                                $('#datagrid_user').datagrid("reload");
                                $.messager.show({
                                    title: '提示信息',
                                    //msg: result.count + "个客户状态更改" +result.message
                                    msg: result.count + result.message
                                });
                            } else {
                                $.messager.show({
                                    title: '提示信息',
                                    msg: result.message
                                });
                            }
                        }, 'json');
                    }
                });
            }else {
                $.messager.alert('提示','请选择需要启用或禁用的客户','info');
            }
        }
    </script><%--toolbar--%>
</body>
</html>
